扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:OURY 来源:blog 2007年10月19日
关键字:
/* || How to print the contents of a simple STL list. Whew! */ #include <iostream.h> #include <string> #include <list> int main (void) { list<string> Milkshakes; list<string>::iterator MilkshakeIterator; Milkshakes.push_back("Chocolate"); Milkshakes.push_back("Strawberry"); Milkshakes.push_front("Lime"); Milkshakes.push_front("Vanilla"); // print the milkshakes Milkshakes.push_front("The Milkshake Menu"); Milkshakes.push_back("*** Thats the end ***"); for (MilkshakeIterator=Milkshakes.begin(); MilkshakeIterator!=Milkshakes.end(); ++MilkshakeIterator) { // dereference the iterator to get the element cout << *MilkshakeIterator << endl; } } |
/* || How to print a simple STL list MkII */ #include <iostream.h> #include <string> #include <list> #include <algorithm> PrintIt (string& StringToPrint) { cout << StringToPrint << endl; } int main (void) { list<string> FruitAndVegetables; FruitAndVegetables.push_back("carrot"); FruitAndVegetables.push_back("pumpkin"); FruitAndVegetables.push_back("potato"); FruitAndVegetables.push_front("apple"); FruitAndVegetables.push_front("pineapple"); for_each (FruitAndVegetables.begin(), FruitAndVegetables.end(), PrintIt); } |
濡傛灉鎮ㄩ潪甯歌揩鍒囩殑鎯充簡瑙T棰嗗煙鏈€鏂颁骇鍝佷笌鎶€鏈俊鎭紝閭d箞璁㈤槄鑷抽《缃戞妧鏈偖浠跺皢鏄偍鐨勬渶浣抽€斿緞涔嬩竴銆�